<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use \Illuminate\Support\Facades\Route;

$uri    = trim(request()->getPathInfo(), '/');
$params = $uri == '' ? [] : explode('/', $uri);
// 将 get-user-info 转为 GetUserInfo
array_studly_case($params);
// 获取到 控制器 和 action
list($controller, $action) = get_controller_action($params);

$namespace = '\App\Http\Controllers\\';
$options   = [
    'domain'     => request()->getHttpHost(),
    'namespace'  => $namespace,
    'middleware' => [],
];

// 统计数据
if (request()->is('statistical/*')) {
    $options['middleware'][] = 'statistics';

    // 统计数据-主账号
    if (request()->is('statistical/user/*')) {
        $options['middleware'][] = 'statistics.main';
    }
}

$controller = $namespace . $controller;
if (method_exists($controller, $action)) {
    Route::group($options, function () use ($uri, $controller, $action) {
        Route::match(['get', 'post', 'option'], $uri, $controller . '@' . $action);
    });
}

